Skip to content

Handle basic query parameters in connection URI #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2021

Conversation

captainju
Copy link
Contributor

Proposed Changes

The current connection method setUri() does not handle query parameters at all, unlike the official Erlang client.
This pull request adds basic query parameters capabilities.
However, due to SSL handling differences between the Erlang client and the Java client, all SSL parameters are not used.
Only the following parameters are used:

  • heartbeat : Heartbeat timeout value in seconds (an integer) to negotiate with the server.
  • connection_timeout : Time in milliseconds (an integer) to wait while establishing a TCP connection to the server before giving up.
  • channel_max : Maximum number of channels to permit on this connection.

(taken from https://www.rabbitmq.com/uri-query-parameters.html)

It is easily extendable for other future query parameters.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

try {
for (String param : rawQuery.split("&")) {
String[] pair = param.split("=");
String key = URLDecoder.decode(pair[0], "US-ASCII");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not use UTF-8 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same charset as in uriDecode line 378, which is used to decode username password and vhost.

    private static String uriDecode(String s) {
        try {
            // URLDecode decodes '+' to a space, as for
            // form encoding.  So protect plus signs.
            return URLDecoder.decode(s.replace("+", "%2B"), "US-ASCII");
        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

https://github.com/rabbitmq/rabbitmq-java-client/pull/672/files#diff-045e321e0fb12f11085653a7ed09f16518f9f21a7c80990c30720958dc17e954R378

@michaelklishin
Copy link
Contributor

@acogoluegnes FYI, I discussed this with @captainju on Slack and suggested that we would consider such a contribution.

@acogoluegnes acogoluegnes added this to the 5.12.0 milestone Feb 22, 2021
@acogoluegnes acogoluegnes merged commit bb6c3cb into rabbitmq:master Feb 22, 2021
@acogoluegnes
Copy link
Contributor

Thanks!

acogoluegnes added a commit that referenced this pull request Feb 22, 2021
With fallback hook, by default empty.

References #672
acogoluegnes added a commit that referenced this pull request Feb 22, 2021
With fallback hook, by default empty.

References #672

(cherry picked from commit b3edb1e)
acogoluegnes added a commit that referenced this pull request Feb 22, 2021
Difference between 6.x and 5.x.

References #640, #642, #672
@captainju captainju deleted the handle_query_parameters branch February 23, 2021 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants